#define _CRT_SECURE_NO_WARNINGS 1
#include <vector>
#include <string>
using namespace std;
class Solution {
public:
    vector<string> ret;
    void _sub(string s, string str, int level)
    {
        if (s.size() == 0) return;
        if (level == 4)
        {
            //cout<<"s="<<s<<endl;
            if (s.size() >= 2 && s[0] == '0') return;
            if (s.size() > 3) return;
            if (stoi(s) > 255) return;
            ret.push_back(str + s);
            return;
        }
        for (int i = 0;i < s.size();++i)
        {
            string tmp = str;
            string nows = s.substr(0, i + 1);
            if (nows.size() >= 2 && nows[0] == '0') return;
            //cout<<"level="<<level<<",i="<<i<<",nows="<<nows<<endl;
            if (nows.size() > 3) return;
            string nexts = s.substr(i + 1, s.size() - i);
            int nums = stoi(nows);
            if (nums > 255 || nums < 0) return;
            tmp += nows + '.';
            _sub(nexts, tmp, level + 1);
        }
    }
    vector<string> restoreIpAddresses(string s)
    {
        string str;
        _sub(s, str, 1);
        return ret;
    }
};